Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mapbox/tiny-sdf

Package Overview
Dependencies
Maintainers
28
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mapbox/tiny-sdf

Browser-side SDF font generator

  • 2.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4M
increased by4.4%
Maintainers
28
Weekly downloads
 
Created

What is @mapbox/tiny-sdf?

@mapbox/tiny-sdf is a JavaScript library that generates tiny signed distance fields (SDF) for text rendering. It is particularly useful for rendering high-quality text in WebGL contexts, such as in maps or other graphics applications where text clarity and performance are important.

What are @mapbox/tiny-sdf's main functionalities?

Generate SDF for a single character

This feature allows you to generate a signed distance field for a single character. The `draw` method takes a character as input and returns a grayscale image representing the SDF.

const TinySDF = require('@mapbox/tiny-sdf');
const tinySDF = new TinySDF();
const sdf = tinySDF.draw('A');
console.log(sdf);

Customizing SDF parameters

You can customize the parameters of the SDF generation, such as the font size, buffer, radius, cutoff, and font family. This allows for greater control over the appearance and quality of the generated SDF.

const TinySDF = require('@mapbox/tiny-sdf');
const tinySDF = new TinySDF(24, 3, 8, 72, 'serif');
const sdf = tinySDF.draw('B');
console.log(sdf);

Rendering text with SDF in WebGL

This feature demonstrates how to use the generated SDF texture in a WebGL context. The SDF can be used as a texture in WebGL to render high-quality text with smooth edges.

const TinySDF = require('@mapbox/tiny-sdf');
const tinySDF = new TinySDF();
const sdf = tinySDF.draw('C');
// Use the SDF texture in a WebGL context
const texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.ALPHA, tinySDF.size, tinySDF.size, 0, gl.ALPHA, gl.UNSIGNED_BYTE, sdf);

Other packages similar to @mapbox/tiny-sdf

Keywords

FAQs

Package last updated on 03 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc